//IP地址
var login_out = "http://59.108.92.239/amucsite/web/";		//apache 数字报的发布地址 根目录 - ip:port
var sso_url = "http://59.108.92.239:9081/SSOv2";		//须知地址
var authCode = "yxweb";

//获得报卡信息的url
var paperInfoUrl = "http://117.78.39.119:8996/amuc/api/pcard/getCurPCardInfo";
var activePaperUrl = "http://117.78.39.119:8996/amuc/api/pcard/activatePaperCard";
var isVipUrl= "http://117.78.39.119:8996/amuc/api/member/level";

//翔宇的地址 + 获取非注册用户读取数字报的过期时间 - 使用的是app的接口
var dueTimeUrl = "http://117.78.36.36:8995/app-if/getConfig?appID=1&jsoncallback=?";
var path="../../../layout/";
//var dsp_url = "http://172.19.33.109:8080";


//弹出窗口位置
var iWidth=360; //弹出窗口的宽度;
var iHeight=490; //弹出窗口的高度;
var iTop = (window.screen.availHeight-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-iWidth)/2+400; //获得窗口的水平位置;
var window_site = "height=490, width=360,top="+iTop+",left="+iLeft+", toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";

//设置cookie
function setCookie(sName, sValue){
	if (sValue == "") sValue = "";
	//cookie过期时间为关闭浏览器时就过期
	document.cookie = sName + "=" + escape(sValue) + ";path=/";
}
//获取cookie
function doGetCookie(strName){
	var theValue = null;
	var aCookie = document.cookie.split("; ");

	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		if (strName == aCrumb[0]) theValue = unescape(aCrumb[1]);
	}
	if (theValue == "0") theValue = "";
	return theValue;
}
//删除cookie
function delCookie(name){
    setCookie(name,"");
}

//每5毫秒自动检测一次用户是否登录（也就是检测cookie是否存在）
window.onload=function(){
	//isLogin()
	window.setInterval("isLogin()",500);

}

//判断处理cookie
function isLogin(){
	var _userId = doGetCookie("username_fouNder");
	var _ssoId = doGetCookie("uid_fouNder");
	console.log(_userId);
	//如果cookie中同时不包含这些，说明cookie中无用户信息，没登录
	if(_userId==undefined|| _userId =="undefined"  || _userId=="" || _userId == null){
	//if(!_userId){
		$("#sso-active").show();
		$("#sso-inactive").hide();
	}else{
		var cookieValue=doGetCookie("username_fouNder");  //将用户名存在cookie中
		$("#sso-active").hide();
		$("#sso-inactive").show();
		$("#uname").text(cookieValue);  //为用户名赋值
	}
}

//sso注册
function register(){
	window.open (sso_url+"/user/register","newwindow", window_site);
}

//sso登录
function ssologin(){
	window.open(sso_url + "/user/ssoLogin?code=" + authCode + "&redirectUrl=" + login_out + "sso/setCookie.html?", "newwindow", window_site);
}

//sso退出。设置好的 cookie会自动失效，只需设置效果即可   
function exit(){
	window.open(sso_url+"/user/ssoLogout?code=" + authCode + "&from="+login_out+"sso/delCookie.html","newwindow", window_site);
	$("#sso-active").hide();
	$("#sso-inactive").css("display","block");

}